home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1995 October / EnigmA AMIGA RUN 01 (1995)(G.R. Edizioni)(IT)[!][issue 1995-10][Aminet 7].iso / Aminet / util / boot / bsd_switch.lha / bsd-switch / bsd-switch.c < prev    next >
C/C++ Source or Header  |  1995-06-18  |  3KB  |  129 lines

  1. /*
  2. ** bsd-switch.c
  3. **
  4. ** Envokes Amiga-Dos, if Left-Shift is pressed.
  5. ** Otherwise it starts NetBSD
  6. **
  7. ** © 1995 - christoph wilhelm
  8. ** 
  9. */
  10.  
  11. /* Global Var's */
  12. struct MsgPort    *port = NULL;
  13. struct IOStdReq   *req  = NULL;
  14. struct Library    *InputBase = NULL;
  15. char              ExecuteString[120];
  16. char              Version[] = "$VER: BSD-Switch 1.0 - © 1995 Christoph Wilhelm ";
  17.  
  18. /* ProtoTypes */
  19. BOOL Setup( void );
  20. BOOL CheckShift( void );
  21. void ShutDown( void );
  22.  
  23. /* Procedures */
  24.  
  25. BOOL Setup() {
  26.    /*
  27.    ** Open Exec-Messageport, IO-Request and 'input.device'
  28.    **
  29.    ** returns TRUE, if succesfull,
  30.    ** FALSE else.
  31.    */
  32.  
  33.    int   error = NULL;
  34.  
  35.    /* Allocate memory for Message-Prot and initialize it!  */
  36.    port = CreatePort("bsd-starter",0);
  37.  
  38.    if( port != NULL ) {
  39.  
  40.       /* Create Standard IO-Request */
  41.       req = CreateStdIO( port );
  42.  
  43.       if( req != NULL ) {
  44.  
  45.          /* ... and finally open the device */
  46.          error = OpenDevice( "input.device", 0, (struct IORequest*) req, 0 );
  47.  
  48.          if( error != NULL )
  49.             DeleteStdIO( req );
  50.          else
  51.             /*
  52.             ** PeekQualifier() must know, where the input.device has its
  53.             ** Library-Base
  54.             */
  55.             InputBase = &req->io_Device->dd_Library;
  56.       }
  57.       else
  58.          DeletePort( port );
  59.    }
  60.  
  61.    if( error == NULL )
  62.       return TRUE;
  63.    else
  64.       return FALSE;
  65. }
  66.  
  67. BOOL CheckShift() {
  68.    BOOL  pressed;
  69.    UWORD qual;
  70.  
  71.    qual = PeekQualifier();          /* Read all pressed Qualifiers */
  72.    if( qual & IEQUALIFIER_LSHIFT )  /* Left-Shift pressed ? */
  73.       pressed = TRUE;
  74.    else
  75.       pressed = FALSE;
  76.  
  77.    return pressed;
  78. }
  79.  
  80. void ShutDown() {
  81.  
  82.    /* This cleans up all used Resources */
  83.    CloseDevice( (struct IORequest *) req );
  84.    DeleteStdIO( req );
  85.    DeletePort( port );
  86. }
  87.  
  88. void main( int argc, char *argv[] ) {
  89.    if( argc < 3 || argc >3 ) {
  90.       printf("\n");
  91.       printf("BSD-Switch - © 1995 Christoph Wilhelm \n");
  92.       printf("\n");
  93.       printf("Usage:   bsd-switch <loadbsd> <kernel> \n");
  94.       printf("         where <loadbsd> represents the directory \n");
  95.       printf("         that holds the 'loadbsd'-command and \n");
  96.       printf("         <kernel> the kernel-directory and its \n"); 
  97.       printf("         name. \n");
  98.       printf("\n");
  99.       printf("Example: 1> BSD-Switch C: devs:kernel/netbsd \n");
  100.       printf("\n");
  101.  
  102.    }
  103.    else {
  104.       if( Setup() ) {
  105.          /*
  106.          ** Left-Shift pressed ?
  107.          */
  108.          if( ! CheckShift() ) {
  109.  
  110.             /* Cleanup and make env: assign */
  111.             ShutDown();
  112.             Execute( "Assign env: ram:", NULL, NULL ); /* loadbsd needs this */
  113.  
  114.             /* Assemble the String to execute */
  115.             strcpy( &ExecuteString[0], argv[1] );
  116.             strcat( &ExecuteString[0], "loadbsd -a " );
  117.             strcat( &ExecuteString[0], argv[2] );
  118.  
  119.             /* and DO IT! */
  120.             Execute( &ExecuteString[0], NULL, NULL ); 
  121.          }
  122.          else
  123.             /* load Amiga-DOS */
  124.             ShutDown();
  125.       }
  126.    }
  127.    exit(0);
  128. }
  129.